package com.tjp.eight.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.tjp.eight.WApplication;

/**
 * Created by Administrator on 2017/3/6.
 */

public class SharePreferencesUtils {
    public static boolean isLogin() {
        if (StringUtils.isNullOrEmpty(getUid()) || StringUtils.isNullOrEmpty(getLoginKey())) {
            return false;
        }
        return true;
    }

    public static void logout() {
        setUid("");
        setUserUrl("");
        setGender("");
        setLoginKey("");
        setName("");
        setLoginKey("");
        setCommetnTips(0);
        setPraseTips(0);
        setWebTextSize(0);
        setMoney("");
    }

    public static void setWebTextSize(int size) {
        SharedPreferences sharedPreferences = WApplication.getwApplication().
                getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("webtextsize", size);
        editor.commit();
    }

    public static int geWebTextSize() {
        SharedPreferences sharedPreferences = WApplication.getwApplication().
                getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return sharedPreferences.getInt("webtextsize", 0);
    }

    public static void setLoginKey(String key) {
        SharedPreferences sharedPreferences = WApplication.getwApplication().
                getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("loginkey", key);
        editor.commit();
    }

    public static String getLoginKey() {
        SharedPreferences sharedPreferences = WApplication.getwApplication().
                getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return sharedPreferences.getString("loginkey", "");
    }

    public static void setUid(String uid) {
        SharedPreferences sh = WApplication.getwApplication().
                getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor e = sh.edit();
        e.putString("uid", uid);
        e.commit();
    }

    public static String getUid() {
        SharedPreferences s = WApplication.getwApplication()
                .getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return s.getString("uid", "");
    }

    public static void setUserUrl(String url) {
        SharedPreferences sharedPreferences = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("url", url);
        editor.commit();
    }

    public static String getUserUrl() {
        SharedPreferences sharedPreferences = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return sharedPreferences.getString("url", "");
    }

    public static void setName(String url) {
        SharedPreferences sharedPreferences = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("name", url);
        editor.commit();
    }

    public static String getName() {
        SharedPreferences sharedPreferences = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return sharedPreferences.getString("name", "");
    }

    public static void setGender(String url) {
        SharedPreferences sharedPreferences = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("gender", url);
        editor.commit();
    }

    public static String getGender() {
        SharedPreferences sharedPreferences = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return sharedPreferences.getString("gender", "");
    }

    public static void setVersion(String version) {
        SharedPreferences sp = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("version_code", version);
        editor.commit();
    }

    public static String getVersion() {
        SharedPreferences store = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return store.getString("version_code", "");
    }

    public static void setPraseTips(int praseTips) {
        SharedPreferences sp = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt("praseTips", praseTips);
        editor.commit();
    }

    public static void setCommetnTips(int commetnTips) {
        SharedPreferences sp = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt("commetnTips", commetnTips);
        editor.commit();
    }

    public static int getCommentTips() {
        SharedPreferences store = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return store.getInt("commetnTips", 0);
    }

    public static int getPraiseTips() {
        SharedPreferences store = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return store.getInt("praseTips", 0);
    }

    public static String getMoney() {
        SharedPreferences store = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        return store.getString("money", "0");
    }

    public static void setMoney(String money) {
        SharedPreferences sp = WApplication.getwApplication().getSharedPreferences(SharedPreferenceConstant.STORE_XML, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("money", money);
        editor.commit();
    }
}
